package com.chinamoney.wppm.util;

import java.util.HashMap;
import java.util.Map;

public class ProcessPointDefinitionUtil {
	
	public static final String NODE_TYPE_SINGLE_APPROVER = "NODE_TYPE_SINGLE_APPROVER";
	
	public static final String NODE_TYPE_MULTIPLE_APPROVER = "MULTIPLE_APPROVER";
	
	private static final Map<String, Map<String, Node>> chain = new HashMap<>();
	
	static {
		Node n1 = new Node(null, "需求提出", "需求部门领导评审", NODE_TYPE_SINGLE_APPROVER);
		Node n2 = new Node("需求提出", "需求部门领导评审", "设计部门领导评审", NODE_TYPE_SINGLE_APPROVER);
		Node n3 = new Node("设计部门领导评审", "设计部门领导评审", "设计部门项目负责人评审", NODE_TYPE_SINGLE_APPROVER);
		Map<String, Node> nodes = new HashMap<>();
		nodes.put(n1.getNodeName(), n1);
		nodes.put(n2.getNodeName(), n2);
		nodes.put(n3.getNodeName(), n3);
		chain.put("电子需求单", nodes);
	}

	public static final String[] EFORM = {"需求提出", "需求部门领导评审", "设计部门领导评审"};
	
	public static String getNextPointName(String processName, String name) {
		String result = "";
		Map<String, Node> nodes = chain.get(processName);
		if(null != nodes && nodes.size() > 0) {
			Node n = nodes.get(name);
			if(null != n) {
				result = n.getNextNodeName();
				if(null == result) result = "";
			}
		}
		return result;
	} 
	
	public static String getNodeType(String processName, String name) {
		String nodeType = "";
		Map<String, Node> nodes = chain.get(processName);
		if(null != nodes && nodes.size() > 0) {
			Node n = nodes.get(name);
			if(null != n) {
				nodeType = n.getNodeType();
			}
			
		}
		return nodeType;
	}
	
	static class Node {
		
		private String preNodeName;
		
		private String nodeName;
		
		private String nextNodeName;
		
		private String nodeType; 
		
		public Node(String preNodeName, String nodeName, String nextNodeName, String nodeType) {
			this.preNodeName = preNodeName;
			this.nodeName = nodeName;
			this.nextNodeName = nextNodeName;
			this.nodeType = nodeType;
		}
		
		public String getPreNodeName() {return preNodeName;}
		public String getNodeName() {return nodeName;}
		public String getNextNodeName() {return nextNodeName;}
		public String getNodeType() {return nodeType;}
		
		@Override
		public boolean equals(Object obj) {
			if(obj == this) return true;
			if(obj instanceof Node){
				Node n = (Node) obj;
				String nPreNodeName = n.getPreNodeName();
				String nNodeName = n.getNodeName();
				String nNextNodeName = n.getNextNodeName();
				String nNodeType = n.getNodeType();
				if(null == nPreNodeName && null == this.preNodeName){
					return true;
				}
				if(null != nPreNodeName && nPreNodeName.equals(this.preNodeName)) {
					return true;
				}
				
				if(null == nNodeName && null == this.nodeName){
					return true;
				}
				if(null != nNodeName && nNodeName.equals(this.nodeName)) {
					return true;
				}
				
				if(null == nNextNodeName && null == this.nextNodeName){
					return true;
				}
				if(null != nNextNodeName && nNextNodeName.equals(this.nextNodeName)) {
					return true;
				}
				
				if(null == nNodeType && null == this.nodeType){
					return true;
				}
				if(null != nNodeType && nNodeType.equals(this.nodeType)) {
					return true;
				}
			}
			return false;
		}
		
		@Override
		public int hashCode() {
			String name = this.preNodeName+this.nodeName + this.nextNodeName+this.nodeType;
			return name.hashCode();
		}
	}
	
//	enum NodeType {
//		
//		SINGLE_APPROVER("SINGLE_APPROVER"), MULTIPLE_APPROVER("MULTIPLE_APPROVER");
//		
//		private String type;
//		
//		NodeType(String type) {
//			this.type = type;
//		}
//		
//		public String toString() {
//			return type;
//		}
//	}
	
	
}
